package zero.springdemo.springquartzdemo.core.quartz

import org.quartz.spi.TriggerFiredBundle
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.config.AutowireCapableBeanFactory
import org.springframework.scheduling.quartz.AdaptableJobFactory
import org.springframework.stereotype.Component

@Component
class MyJobFactory : AdaptableJobFactory() {
    @Autowired
    private lateinit var capableBeanFactory: AutowireCapableBeanFactory

    override fun createJobInstance(bundle: TriggerFiredBundle): Any {
        //调用父类的方法
        val jobInstance = super.createJobInstance(bundle)
        //进行注入,这属于Spring的技术,不清楚的可以查看Spring的API.
        capableBeanFactory.autowireBean(jobInstance)
        return jobInstance

    }

}